package com.tarena.lbs.activity.controller;

import com.tarena.lbs.activity.pojo.param.ActivityAddParam;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 活动相关功能接口
 */
@RestController
@Slf4j
@Tag(name = "活动服务", description = "活动服务")
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    @Operation(summary = "商家活动列表")
    @PostMapping("/admin/marketing/marketingActivity/info/list")
    public Result<PageResult<ActivityVO>> pageList(@RequestBody ActivityAddParam param) throws BusinessException {
        PageResult<ActivityVO> voPage = activityService.pageList(param);
        System.out.println(param);
        return new Result<>(voPage);
    }

    @Operation(summary = "商家活动保存")
    @PostMapping("/admin/marketing/marketingActivity/info/update")
    public Result<Void> activityupdate(@RequestBody ActivityAddParam param) throws BusinessException, ParseException {
        return Result.success();
    }

    @Operation(summary = "商家活动保存")
    @PostMapping("/admin/marketing/marketingActivity/info/save")
    public Result<Void> activitySave(@RequestBody ActivityAddParam param) throws BusinessException, ParseException {
        activityService.save(param);
        return Result.success();
    }

    @Operation(summary = "商家活动详情")
    @GetMapping("/admin/marketing/marketingActivity/info/detail/{id}")
    public Result<ActivityVO> activityDetail(@PathVariable("id") Integer id) throws BusinessException {
        ActivityVO activityVO = activityService.detail(id);
        return new Result<>(activityVO);
    }

    @Operation(summary = "修改活动启动状态")
    @PostMapping("/admin/marketing/marketingActivity/info/updateStatus")
    public Result<Void> updateActivityStatus(@RequestBody ActivityAddParam param) throws BusinessException {
        System.out.println(param);
        activityService.updateActivityStatus(param);
        return Result.success();
    }


    @Operation(summary = "删除活动")
    @PostMapping("/admin/marketing/marketingActivity/info/delete")
    public Result<Void> deleteActivity(@RequestBody ActivityAddParam param) throws BusinessException {
        System.out.println(param);
        activityService.deleteActivity(param);
        return Result.success();
    }


    @Operation(summary = "各状态活动数量")
    @GetMapping("/admin/marketing/marketingActivity/getArticleStatusMap")
    public Result<Map<String,Integer>> getArticleStatusMap() {
        Map<String,Integer> statusMap =activityService.getArticleStatusMap();
        return new Result<>(statusMap);
    }
}
